#region Using

using System;
using System.Collections.Generic;

#endregion

namespace SemanticEngine.Apml
{
	public class ApmlProfile : ValidationBase
	{

		#region Properties

		private string _Name;

		public string Name
		{
			get { return _Name; }
			set { _Name = value; }
		}

		private bool _IsDefaultProfile;

		public bool IsDefaultProfile
		{
			get { return _IsDefaultProfile; }
			set { _IsDefaultProfile = value; }
		}

		private List<Concept> _Concepts = new List<Concept>();

		public List<Concept> Concepts
		{
			get { return _Concepts; }
		}

		private List<Source> _Sources = new List<Source>();

		public List<Source> Sources
		{
			get { return _Sources; }
		}

		#endregion

		#region Methods

		public void AddConcepts(params string[] concepts)
		{
			foreach (string concept in concepts)
			{
				Concept c = new Concept(concept);
				Concepts.Add(c);
			}
		}

		public void AddConcept(string name, double rank)
		{
			Concept c = new Concept(name, rank);
			Concepts.Add(c);
		}

		public void AddConcept(string name, double rank, string from)
		{
			Concept c = new Concept(name, rank, from);
			Concepts.Add(c);
		}

		public void AddConcept(string name, double rank, string from, DateTime dateUpdated)
		{
			Concept c = new Concept(name, rank, from, dateUpdated);
			Concepts.Add(c);
		}

		/// <summary>
		/// Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
		/// </summary>
		/// <returns>
		/// A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
		/// </returns>
		public override string ToString()
		{
			return Name;
		}

		/// <summary>
		/// Reinforces the business rules by adding rules to the
		/// broken rules collection.
		/// </summary>
		protected override void Validate()
		{
			AddRule("Concepts or Sources", "An ApmlProfile must contain at least one Concept or Source", Concepts.Count == 0 && Sources.Count == 0);

			foreach (Concept concept in Concepts)
			{
				if (!concept.IsValid)
				{
					AddRule("Concepts", concept.ValidationMessage, true);
					break;
				}
			}

			foreach (Source source in Sources)
			{
				if (!source.IsValid)
				{
					AddRule("Sources", source.ValidationMessage, true);
					break;
				}
			}
		}

		#endregion
	}
}
